home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
AUXCOM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
14KB
|
572 lines
#include "pt.h"
#include "io.h"
#include "string.h"
#include "stdlib.h"
#include "direct.h"
int pascal
/* XTAG:quitPoint */
quitPoint(fn, noSave)
int fn, noSave;
{
extern unsigned char msgBuffer[];
extern struct window *windowList;
extern struct window *hiddenList;
extern struct openFile *files;
extern int i43lines;
#ifdef OVERLAYS
extern int overlayState;
#endif
extern unsigned char startDirectory[];
extern unsigned char startDrive;
extern struct openFile *files;
register struct window *w2;
register int j;
unsigned char *fileName;
int i, n;
int fid;
/* create (or truncate) the last state file */
setDefaultDrive(startDrive);
chdir(startDirectory);
fid = creatls("pt.las", 0);
if( fid >= 0 ) {
sprintf(msgBuffer, "%d \r\n", i43lines);
writels(fid, msgBuffer, strlen(msgBuffer));
}
if( !noSave )
goto noChanges;
n = 0;
w2 = windowList;
while( 1 ) {
if( w2 == NULL ) {
/* gone through both windowList and hiddenList? */
if( n == 1 )
break; /* ifm we are done */
/* if not do hiddenList */
n = 1; /* remember that we already did windowList */
w2 = hiddenList;
continue;
}
/* see if the file has been edited */
if( files[w2->fileId].isChanged )
goto areChanges;
w2 = w2->nextWindow;
}
goto noChanges;
areChanges:
fileName = getInput(
"Are you sure you want to discard all changes? ", "y", 1);
if( tolower(fileName[0]) != 'y' ) {
msg("Quit-Discard Edits cancelled", 1);
return 0;
}
noChanges:
n = 0;
w2 = windowList;
while( 1 ) {
if( w2 == NULL ) {
/* gone through both windowList and hiddenList? */
if( n == 1 )
break; /* ifm we are done */
/* if not do hiddenList */
n = 1; /* remember that we already did windowList */
w2 = hiddenList;
continue;
}
if( fn == FQUITASK )
j = 1; /* ask about saving */
else
j = 0; /* save without asking */
if( fn == FQUITNOSAVE )
j = 2; /* do not ask or save */
i = closeWindow(w2, j, 0);
if( i == -1 ) {
msg("Window close failed, quit cancelled", 3);
goto noQuit;
}
/* record the state in the last state file */
if( fid >= 0 ) {
sprintf(msgBuffer, "%d %d %d %d %d %s \r\n",
w2->row1, w2->col1, w2->row2, w2->col2,
w2->numTopline, files[w2->fileId].origName);
writels(fid, msgBuffer, strlen(msgBuffer));
}
w2 = w2->nextWindow;
}
/* reset the mouse */
termMouse();
n = 1;
goto ret;
noQuit:
n = 0;
ret:
if( fid >= 0 )
closels(fid);
return n;
}
unsigned char * pascal
/* XTAG:getSelection */
getSelection(s)
unsigned char *s;
{
extern long selBegin, selEnd;
extern struct window *selWindow;
register unsigned char *p;
long cp;
register int fid;
p = s;
cp = selBegin;
fid = selWindow->fileId;
while( cp <= selEnd ) {
*p++ = readChar(fid, cp++);
if( p-s >= 63 )
break;
}
*p = '\0';
return s;
}
void pascal
/* XTAG:matchChar */
matchChar()
{
extern struct window *selWindow;
extern long selBegin, selEnd;
register unsigned char ch;
long cp, fSize;
unsigned char ch1, ch2;
int n, matchDirection, nLines;
cp = selBegin;
ch = readChar(selWindow->fileId, cp);
switch( ch ) {
case '(': ch1 = '('; ch2 = ')'; matchDirection = 1; break;
case ')': ch1 = ')'; ch2 = '('; matchDirection = -1; break;
case '[': ch1 = '['; ch2 = ']'; matchDirection = 1; break;
case ']': ch1 = ']'; ch2 = '['; matchDirection = -1; break;
case '{': ch1 = '{'; ch2 = '}'; matchDirection = 1; break;
case '}': ch1 = '}'; ch2 = '{'; matchDirection = -1; break;
default: ch1 = ' '; ch2 = ' '; matchDirection = -1; break;
}
if( ch1 == ' ' ) {
msg("Matching for (, ), [, ], {, and } only", 1);
return;
}
n = 1; /* n==0 ==> we found the matching character */
nLines = 0;
fSize = fileSize(selWindow->fileId);
while( 1 ) {
cp += matchDirection;
ch = readChar(selWindow->fileId, cp);
if( ch == ch1 )
++n;
else if( ch == ch2 )
--n;
else if( ch == '\n' )
++nLines;
if( n == 0 || cp == 0 || cp >= fSize )
break;
}
if( n == 0 ) {
selBegin = selEnd = cp;
/* put the selection on the third line */
if( selBegin >= selWindow->posBotline
|| selBegin < selWindow->posTopline ) {
/* remember where we came from */
selWindow->rowLastline = selWindow->numTopline;
n = 3;
cp = prevLine(selWindow->fileId, selBegin, &n);
selWindow->posTopline = cp;
/* recalculate the line number by letting */
/* prevLine count as far back as it can */
n = 30000;
prevLine(selWindow->fileId, cp, &n);
selWindow->numTopline = n + 1;
}
redrawBox(selWindow->row1, selWindow->col1,
selWindow->row2, selWindow->col2);
updateScreen(selWindow->row1, selWindow->row2);
} else
msg("No matching character was found.", 1);
}
int pascal
/* XTAG:getUnixState */
getUnixState(fileId)
int fileId;
{
extern unsigned char msgBuffer[];
extern unsigned char textBuffer[];
extern int unixMode;
long cp, limit;
int fileUnixMode;
/* if unixMode is 0 or 1 then that+1 is the window's unixMode */
if( unixMode == 0 )
return 1;
else if( unixMode == 1 )
return 3;
/* otherwise, sample the first 300 characters */
/* if no CRs are found then assume it is a UNIX file */
/* if a CR is found, then it is a DOS file */
cp = 0L;
limit = fileSize(fileId) - 1;
if( limit > 300 )
limit = 300;
fileUnixMode = 3;
while( cp < limit ) {
if( readChar(fileId, cp) == '\r' ) {
fileUnixMode = 1;
break;
}
++cp;
}
return fileUnixMode;
}
int pascal
/* XTAG:indentToShowSelection */
/* CPC 4-26-88 */
indentToShowSelection(selCol)
int selCol; /* the column where the first character of */
/* the selection is */
/* CPC 4-26-88 */
{
extern unsigned char msgBuffer[];
extern struct window *selWindow;
extern long selBegin, selEnd;
register struct window *rselWindow;
long longIndent;
int dummy, col, windowWidth, indent;
int originalIndent;
rselWindow = selWindow;
originalIndent = rselWindow->indent;
/* find the column the selection starts in */
/* CPC 4-26-88 */
if( selCol == -1 )
(void)posToxy(rselWindow, selBegin, &dummy, &col);
else
col = selCol;
/* CPC 4-26-88 */
/* posToxy subtracts off the current indent so add it back in */
/* posToxy adds in rselWindow->col1 so subtract it off */
col += rselWindow->indent - rselWindow->col1;
windowWidth = rselWindow->col2 - rselWindow->col1 - 1;
/* if the selection is right of the window, change the indent */
if( (col > (windowWidth+rselWindow->indent)) ) {
indent = col - (windowWidth>>1);
/* figure the column of the end of the selection */
/* add window width / 2 to put it in the */
/* middle of the window */
longIndent = (selEnd - selBegin) + (long)indent;
if( longIndent < (long)col )
rselWindow->indent = (int)longIndent;
else
rselWindow->indent = indent;
} else if( (col < rselWindow->indent) ) {
/* if the selection is left of the window change the indent */
/* change the indent back to zero if this will still leave */
/* the beginning of the selection in the left half of the */
/* window */
indent = col - (windowWidth>>1);
if( indent < 0 )
indent = 0;
rselWindow->indent = indent;
}
/* indicate on return whether you actually changed the indent */
return (originalIndent != rselWindow->indent);
}
void pascal
/* XTAG:doGoSel */
doGoSel(w)
struct window *w;
{
extern struct window *selWindow;
extern long selBegin, selEnd;
extern int linesOverFind;
extern int debug;
register struct window *rselWindow;
register int n;
int i, fid;
long cp, toCp;
rselWindow = selWindow;
/* remember where we came from */
w->rowLastline = w->numTopline;
/* n is the number of lines to move */
fid = rselWindow->fileId;
cp = rselWindow->posTopline;
i = linesOverFind;
/* find the number of lines in the window */
i = rselWindow->row2 - rselWindow->row1 - 2;
if( linesOverFind > i )
/* if linesOverFind would place it outside the */
/* window then put it in the middle